#!/usr/bin/python3

import subprocess
import os
def RUN_FASTAPI():
    if not os.path.exists("main.py"):
        print("当前工作目录下不存在main.py文件，请确保在正确的目录下执行此脚本。")
        return
    command = "nohup fastapi run --host 0.0.0.0 --port 8001 > nohup.out 2>&1 &"
    try:
        subprocess.run(command, shell=True, check=True)
        print("FastAPI项目已在后台成功启动，日志输出到nohup.out文件。")
    except subprocess.CalledProcessError as e:
        print(f"启动FastAPI项目时出错: {e}")
if __name__ == "__main__":
    RUN_FASTAPI()

